import React from 'react'
import ReactDOM from 'react-dom'
import { createStore, applyMiddleware, compose } from 'redux'
import { Provider } from 'react-redux'
import createSagaMiddleware from 'redux-saga'
import rootSaga from '@/app/Models/sagas'
// import { BrowserRouter } from 'react-router-dom'
import { ConnectedRouter, routerMiddleware } from 'react-router-redux'
import createHistory from "history/createBrowserHistory"
import rootReducer from '@/app/Models/reducers/index'
import { middleware } from '@/utils/http'
import App from "./App"
import registerServiceWorker from './registerServiceWorker'

const sagaMiddleware = createSagaMiddleware()
const history = createHistory()
const routeMiddleware = routerMiddleware(history)
const store = createStore(rootReducer, compose(
    applyMiddleware(routeMiddleware, sagaMiddleware),
    window.devToolsExtension ? window.devToolsExtension() : func => func
))

sagaMiddleware.run(rootSaga)

const app = (
    <Provider store={store}>
        <ConnectedRouter history={history}>
            <App />
        </ConnectedRouter>
    </Provider>
)

// 传递给http中使用
middleware(history)

ReactDOM.render(app, document.getElementById("root"));
registerServiceWorker();